package pl.edu.pk.mech.kkbus.repository;

import static pl.edu.pk.mech.kkbus.staticstrings.NameEntity.NAME_ENTITY_SCHEDULE;
import static pl.edu.pk.mech.kkbus.staticstrings.NameEntity.NAME_ENTITY_USERS;
import static pl.edu.pk.mech.kkbus.staticstrings.ScheduleProperty.SCHEDULE_DAYS;
import static pl.edu.pk.mech.kkbus.staticstrings.ScheduleProperty.SCHEDULE_HOURS;
import static pl.edu.pk.mech.kkbus.staticstrings.ScheduleProperty.SCHEDULE_KEY_USER;
import static pl.edu.pk.mech.kkbus.staticstrings.UserProperty.USER_EMAIL;
import pl.edu.pk.mech.kkbus.datastore.common.SynchronizeCommon;
import pl.edu.pk.mech.kkbus.model.Pojo;
import pl.edu.pk.mech.kkbus.model.Schedule;
import pl.edu.pk.mech.kkbus.model.User;

import com.google.appengine.api.datastore.Entity;

public class ScheduleDAO extends BaseDAO{

	@Override
	public void fillProperty(Pojo pojo, Entity entity) {
		Schedule schedule = (Schedule)pojo;
		  entity.setProperty(SCHEDULE_DAYS, schedule.getDays());
		  entity.setProperty(SCHEDULE_HOURS, schedule.getHours());
		  entity.setProperty(SCHEDULE_KEY_USER, schedule.getIdUser());
	}
	
	public Schedule getScheduleByIdUser(long id) {
		  Schedule schedule = null;
		  Iterable<Entity> entityList = SynchronizeCommon.listEntities(NAME_ENTITY_SCHEDULE, SCHEDULE_KEY_USER, String.valueOf(id));
		  for (Entity entity : entityList) {
			  schedule = new Schedule(entity);
		  }
		  return schedule;
	}
}
